{% extends 'base.html' %}

{% block title %}博客{% endblock title %}
{% block content %}
<ul>
    {% for article in latest_article_list %}
    <li>
        <article>
            <header>
                <h1>
                    <a href="{{ article.get_absolute_url }}">{{ article.title }}</a>
                </h1>
            </header>
            <div>
                <p>{{ article.body|slice:'50' }}</p>
                <div>
                    <span>阅读数：{{ article.views }}</span>
                    <a href="{{ article.get_absolute_url }}">查看详情 <span>→</span></a>
                </div>
            </div>
        </article>
    </li>
    {% empty %}
    <li>
        <div>暂时还没有发布的文章！</div>
    </li>
    {% endfor %}
</ul>
<div>
    <span>
        <!-- 如果不是第一页，则显示上翻按钮 -->
        {% if articles.has_previous %}
            <a href="?page=1">
                &laquo; 1
            </a>
            <span>...</span>
            <a href="?page={{ articles.previous_page_number }}">
                {{ articles.previous_page_number }}
            </a>
        {% endif %}

        <!-- 当前页面 -->
        <span>
            {{ articles.number }}
        </span>

        <!-- 如果不是最末页，则显示下翻按钮 -->
        {% if articles.has_next %}
            <a href="?page={{ articles.next_page_number }}">
                {{ articles.next_page_number }}
            </a>
            <span>...</span>
            <a href="?page={{ articles.paginator.num_pages }}">
                {{ articles.paginator.num_pages }} &raquo;
            </a>
        {% endif %}
    </span>
</div>
{% endblock content %}